//
// Created by Semir on 2020/4/26.
//

#include <iostream>
#include <deque>
#include <string>
#include <map>
#include <vector>
#include <cmath>
#include <set>

using namespace std;

struct Node {
    int x;
    int y;
//    friend bool operator == (const Node &n1, const Node &n2) {
//        return n1.x == n2.x && n1.y == n2.y;
//    }
    friend bool operator < (const Node &n1, const Node &n2) {
        if (n1.x < n2.x) {
            return true;
        } else if (n1.x == n2.x) {
            return n1.y < n2.y;
        } else {
            return false;
        }
    }
//    friend bool operator > (const Node &n1, const Node &n2) {
//        return n1.x > n2.x && n1.y > n2.y;
//    }
};

int group, n;
set<Node> A;
set<Node> B;

int main() {
    cin >> group;
    for (int i = 0; i < group; i++) {
        cin >> n;
        A.clear();
        B.clear();
        bool flag = false;
        for (int j = 0; j < n; j++) {
            Node tmp;
            cin >> tmp.x >> tmp.y;
            A.insert(tmp);
        }
        for (int j = 0; j < n; j++) {
            Node tmp;
            cin >> tmp.x >> tmp.y;
            B.insert(tmp);
            if (A.count(tmp) > 0) {
                flag = true;
            }
        }
        if (flag) {
            cout << "0.000" << endl;
            continue;
        }
        double min = 9999999999.9;
        for (set<Node>::iterator iterA = A.begin(); iterA != A.end(); iterA++) {
            int xA = (*iterA).x;
            int yA = (*iterA).y;
            for (set<Node>::iterator iterB = B.begin(); iterB != B.end(); iterB++) {
                int xB = (*iterB).x;
                int yB = (*iterB).y;
                double tmp = (xB - xA) * (xB - xA) + (yB - yA) * (yB - yA);
                if (tmp < min) {
                    min = tmp;
                }
            }
        }
        min = sqrt(min);
        printf("%.3f\n", min);
    }
    return 0;
}